package com.sky.controller.user;

import com.sky.result.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.web.bind.annotation.*;

@RestController
@Slf4j
@RequestMapping("/user/shop")
@Api(tags = "店铺控制接口")
public class ShopUserController {

    private static final String SHOP_STATUS = "SHOP_STATUS";

    @Autowired
    private RedisTemplate redisTemplate;

    @GetMapping("/status")
    @ApiOperation("获取店铺营业状态")
    public Result<Integer> getStatus(){
        log.info("[获取营业状态]");
        Integer status = (Integer) redisTemplate.opsForValue().get(SHOP_STATUS);
        // 如果返回时null，我们做默认处理，最终解释问产品
        if (status == null){
            log.info("[第一次读取时，没有营业状态，自己设置为1]");
            redisTemplate.opsForValue().set(SHOP_STATUS,1);
            status = 1;
        }
        return Result.success(status);
    }
}
